// useStatusGuard.ts/js
export function useStatusGuard() {
    const normalizeStatus = (s) => {
      if (s == null) return null
      if (typeof s === 'string') {
        const v = s.trim().toLowerCase()
        if (v === '0' || v === 'active')  return 0
        if (v === '1')  return 1
        if (v === '2')    return 2
        if (v === '3' || v === 'stopped') return 3
        if (v === '4') return 4
        return Number.isFinite(+v) ? +v : null
      }
      return Number(s)
    }
    const isStatus = (s, expect) => normalizeStatus(s) === normalizeStatus(expect)
    const showIf = (row, expect, getValue, placeholder = '—') =>
      isStatus(row?.status, expect) ? getValue(row) : placeholder
    const formatterIf = (expect, getValue, placeholder = '—') =>
      (row) => isStatus(row?.status, expect) ? getValue(row) : placeholder
  
    return { normalizeStatus, isStatus, showIf, formatterIf }
  }
  